package com.wnxy.controller;


import com.wnxy.entity.ProductType;
import com.wnxy.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品类型表 前端控制器
 * </p>
 *
 * @author 林夕
 * @since 2023-03-11 04:45:21
 */
@RestController
@RequestMapping("/weaponType")
public class ProductTypeController {

    @Autowired
    ProductTypeService productTypeService;

    @Autowired
    RedisTemplate<String, Object> stringObjectRedisTemplate;

    @RequestMapping("/allTypes")
    public List<ProductType> allTypes(){
        ValueOperations<String, Object> opsForValue = stringObjectRedisTemplate.opsForValue();
        List<ProductType> typeList = (List<ProductType>) opsForValue.get("typeList");
        if (typeList == null){
            typeList = productTypeService.list();
            opsForValue.set("typeList", typeList);
        }
        return typeList;
    }

    @RequestMapping("/typeDetail")
    public ProductType typeDetail(Integer weaponTypeId){
        ProductType type = productTypeService.getById(weaponTypeId);
        return type;
    }

}

